<script setup lang="ts">
import { reactive } from 'vue';
import type {  FormRules } from 'element-plus';
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router';
// import { fetchTest } from '@/api';
// import { fetch } from '@tauri-apps/plugin-http';
// import router from './router';
interface LoginInfo {
    username: string;
    password: string;
}
const router = useRouter();
const param = reactive<LoginInfo>({
    username:'',
    password: '',
});
let title = reactive({
    name:'RP管理系统'
}) 

const rules: FormRules = {
    username: [
        {
            required: true,
            message: '请输入用户名',
            trigger: 'blur',
        },
    ],
    password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
};

// const getData = async () => {
//     const res2 = await fetchTest()
//     title.name = res2.data.result[0].title
//     console.log("res2", title)
// }
const submitForm = async () => {
    // const response = await fetch('https://api.oick.cn/api/lishi', {
    //     method: 'GET',
    // });
    // const response2 = await fetch('./mock/user.json', {
    //     method: 'GET',
    // });

    // console.log("response", response.json())
    // console.log("response2", response2.json())
   if(param.username == 'admin'&&param.password == 'admin'){
    ElMessage.success('登录成功');
    router.push('/home');
   }else{
    ElMessage.error('用户名或密码错误')
   }

};
</script>
<template>
    <div class="login-bg">
      <div class="login-container-left">
        </div>
        <div class="login-container-right">
            <div class="login-header">
                <img class="logo mr10" src="../../assets/img/logo.svg" alt="" />
                <div class="login-title">{{title.name}}</div>
            </div>
            <el-form :model="param" :rules="rules" ref="login" size="large">
                <el-form-item prop="username">
                    <el-input v-model="param.username" placeholder="用户名admin">
                        <template #prepend>
                            <el-icon>
                                <User />
                            </el-icon>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="密码admin"
                        v-model="param.password"
                        @keyup.enter="submitForm()"
                    >
                        <template #prepend>
                            <el-icon>
                                <Lock />
                            </el-icon>
                        </template>
                    </el-input>
                </el-form-item>
                <div class="pwd-tips">
                    <el-checkbox class="pwd-checkbox" label="记住密码" />
                    <el-link type="primary" @click="$router.push('/reset-pwd')" disabled>忘记密码</el-link>
                </div>
                <el-button class="login-btn" type="primary" size="large" @click="submitForm()">登录</el-button>
                <p class="login-tips">Tips : 用户名和密码随便填。</p>
                <p class="login-text">
                    没有账号？<el-link type="primary" disabled @click="$router.push('/register')">立即注册</el-link>
                </p>
            </el-form>
        </div>
    </div>
</template>

<style scoped>
.login-bg {
    display: flex;
    align-items: center;
    justify-content: center; 
    width: 100%;
    height: 100vh;
    /* background: url(./assets/img/login-bg.jpg) center/cover no-repeat; */
}
.login-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
}
.logo {
    width: 35px;
}
.login-title {
    font-size: 22px;
    color: #333;
    font-weight: bold;
}
.login-container-left{
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70%;
    height: 100%;
     background: url(../../assets/img/login-bg.jpg) center/cover no-repeat;
}
.login-container-right {
    width: 450px;
    border-radius: 5px;
    background: #fff;
    padding: 40px 50px 50px;
    box-sizing: border-box;
    
}
.pwd-tips {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    margin: -10px 0 10px;
    color: #787878;
}
.pwd-checkbox {
    height: auto;
}
.login-btn {
    display: block;
    width: 100%;
}
.login-tips {
    font-size: 12px;
    color: #999;
}
.login-text {
    display: flex;
    align-items: center;
    margin-top: 20px;
    font-size: 14px;
    color: #787878;
}
</style>
